import pyttsx3


class ttsx(object):
    def __init__(self, rate=-10):
        self.engine = pyttsx3.init()
        self.rate = rate

    def sayText(self, str):
        # 语速
        rate = self.engine.getProperty('rate')
        self.engine.setProperty('rate', rate + self.rate)

        # 音量
        # volume = self.engine.getProperty('volume')
        # engine.setProperty('volume', volume - 0.25)

        # 声音
        # voices = self.engine.getProperty('voices')
        # for voice in voices:
        #   self.engine.setProperty('voice', voice.id)
        #   print(voice.id)

        self.engine.say(str)
        self.engine.runAndWait()

    def write_to_file(self, value, file):
        self.engine.save_to_file(value, file)
        self.engine.runAndWait()



